<?php

class Database{
    var $_ready = false;
    
    var $_dbcon;
    
    var $_rows_affected = 0;
    
    var $_num_rows = 0;
    
    var $_insert_id = 0;
    
    function __contruct($host, $db, $user, $pass){
        
        if(!$this->_ready){
            $this->_dbcon = @mysqli_connect($host, $user, $pass, $db);
        }

        if (mysqli_connect_error()) {
            die('Connect Error (' . mysqli_connect_errno() . ') '
                    . mysqli_connect_error());
                    
            $this->_ready = false;
        }
        else{
            $this->_ready = true;
        }
    }
    
    function query($query){
        
        if($this->_ready){
            $result = mysqli_query($this->_dbcon, $query);
            
            if ( preg_match( '/^\s*(create|alter|truncate|drop) /i', $query ) ) {
		
    		} elseif ( preg_match( '/^\s*(insert|delete|update|replace) /i', $query ) ) {
    		  
    			$this->_rows_affected = mysqli_affected_rows( $this->_dbcon );
                
                
    			// Take note of the insert_id
    			if ( preg_match( '/^\s*(insert|replace) /i', $query ) ) {
    				$this->_insert_id = mysqli_insert_id($this->_dbcon);
    			}

                
            
    		} else {
    		  
              
              
    		}
            
        }
        
        return $val;
        
    }
    
}


?>